package org.laizili.solution.leetcode;

import org.laizili.structure.list.ListNode;

/**
 * <a href="https://leetcode-cn.com/problems/linked-list-cycle/">141. 环形链表</a>
 * <p>
 * tags: 链表; 快慢指针
 * </p>
 */
public class Problem141 {
    public static class Solution {
        public boolean hasCycle(ListNode head) {
            ListNode fastPointer = head;
            ListNode slowPointer = head;
            while (fastPointer != null && fastPointer.next != null) {
                fastPointer = fastPointer.next.next;
                if (slowPointer == fastPointer) {
                    return true;
                }
                slowPointer = slowPointer.next;
            }
            return false;
        }
    }
}
